package com.whzykj.ctrl;

import com.jfinal.core.Controller;
import com.whzykj.model.Article;
import com.whzykj.model.GoodsInfo;

public class WapController extends Controller{
	/**
	 * 显示公告详细描述页面(H5)
	 * 公告详情页用法：http://112.124.127.38:8081/bcy/wap/notice/公告编号	示例：http://112.124.127.38:8081/bcy/wap/notice/1
	 */
	public void notice(){
		int noticeid=this.getParaToInt(0);
		String sql="SELECT * from article where ARTICLE_KIND=1 and REF_ID="+noticeid;
		Article article=Article.dao.findFirst(sql);
		this.setAttr("article", article);
		this.renderJsp("/mobile/notice.jsp");
	}
	
	/**
	 * 显示商品详细描述页面(H5)
	 * 商品详情页用法：http://112.124.127.38:8081/bcy/wap/goods/商品ID-站点ID  示例：http://112.124.127.38:8081/bcy/wap/goods/7-26
	 */
	public void goods(){
		int goodsid=this.getParaToInt(0);		// 获取商品ID
		Integer station_id=this.getParaToInt(1);	// 	获取站点ID
		System.out.println(station_id);
		StringBuffer sql=new StringBuffer("SELECT gi.APP_NAME,gi.GOODS_PLACE,gi.GOODS_SPEC,d.DICT_NAME as PACKING,gi.BIG_IMG_URL,(p.SALE_PRICE-p.MINUS_PRICE) as GOODS_PRICE,");
		sql.append(" gi.GOODS_DETAIL,(s.STORE_NUM-s.SALE_NUM) as GOODS_STORE,s.LIMIT_NUM ");
		sql.append(" from goodsinfo gi ");
		sql.append(" inner join price p on gi.GOODS_ID = p.GOODS_ID ");
		sql.append(" inner JOIN store s on gi.GOODS_ID = s.GOODS_ID ");
		sql.append(" INNER JOIN dictionary d ON gi.GOODS_PACKING=d.DICT_CODE ");
		sql.append(" where TO_DAYS(p.SET_DATE)=TO_DAYS(NOW()) AND TO_DAYS(s.SET_DATE)=TO_DAYS(NOW()) AND  gi.GOODS_ID="+goodsid);
		if(station_id!=null && station_id!=0){
			sql.append( " AND p.STATION_ID="+station_id);
		}
		GoodsInfo goodsinfo=null;
		try {
			goodsinfo = GoodsInfo.me.findFirst(sql.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		this.setAttr("goods", goodsinfo);
		this.renderJsp("/mobile/goods.jsp");
	}
	
	/**
	 * 显示帮助详细描述页面（H5）
	 * 帮助页面用法：http://112.124.127.38:8081/bcy/wap/help
	 */
	public void help(){
//		int id=this.getParaToInt(0);
//		String sql="SELECT * from article where ARTICLE_KIND=3 and REF_ID="+id;
//		Article article=Article.dao.findFirst(sql);
//		this.setAttr("article", article);
//		this.renderJsp("/mobile/help.jsp");
		this.renderJsp("/mobile/helpinfo.jsp");
	}
	
	/**
	 * 转到帮助页面
	 */
	public void tohelp(){
		this.renderJsp("/mobile/helpinfo.jsp");
	}
	
	/**
	 * 关于页面展示
	 * 关于页面用法：http://112.124.127.38:8081/bcy/wap/aboutus
	 */
	public void aboutus(){
		this.renderJsp("/mobile/aboutus.jsp");
	}
	
	/**
	 * 进入到默认显示页面
	 */
	public void defaultPage(){
		this.renderJsp("/mobile/default.jsp");
	}
	
	/**
	 * 进入到大额充值银行信息页面
	 * 访问路径：http://localhost:8080/bcy/wap/bank
	 */
	public void bank(){
		this.renderJsp("/mobile/bank.jsp");
	}
	
	/**
	 * 
	 */
	public void orderdetails(){
		this.renderJsp("/mobile/orderDetails.jsp");
	}
}
